package icu.qx.diagram.controller;


import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import icu.qx.diagram.domain.Sales;
import icu.qx.diagram.domain.WorkReport;
import icu.qx.diagram.service.IWorkReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/diagram/workReport")
public class WorkReportController extends BaseController{
    private final IWorkReportService workReportService;
    @Autowired
    public WorkReportController(IWorkReportService workReportService){this.workReportService=workReportService;}

    /**
     * 查询报工统计
     */
    @RequiresPermissions("diagram:workReport:list")
    @GetMapping("/list")
    public TableDataInfo list(WorkReport workReport)
    {
        startPage();
        List<WorkReport> list=workReportService.selectWorkReportList(workReport);
        for(WorkReport w:list){
            w.setCreatorName(SecurityUtils.getUsername());
        }
        return  getDataTable(list);
    }
    /**
     * 导出报工统计
     */
    @RequiresPermissions("diagram:workReport:export")
    @Log(title = "产量统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkReport workReport) {
        List<WorkReport> list = workReportService.selectWorkReportList(workReport);
        ExcelUtil<WorkReport> util = new ExcelUtil<>(WorkReport.class);
        util.exportExcel(response, list, "报工统计数据");
    }
}
